function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["column"];
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { EditOutlined, HolderOutlined, MoreOutlined, VerticalAlignBottomOutlined, VerticalAlignMiddleOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
import { Checkbox, Divider, Popover, Space } from 'antd';
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
import ReactDOM from 'react-dom';
import { Resizable } from 'react-resizable';
import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';
import { Tooltip } from "../../antd/tooltip";
import { TableContext } from "../base/common";
import { convertStyle, cssVar, domContains, getScrollBarInfo, useDraggableSort, useIUPEffect, useRefCallback, useReturnCallback, util } from "../util";
import { FilterIcon } from "./filter";
import { OrderIcon } from "./order";

/**
 * 拖拽调整列宽
 * @param propColumnIndex
 * @param resizable
 * @param width
 * @param restProps
 * @constructor
 */
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var HeaderCellResize = function HeaderCellResize(_ref) {
  var _ref$column = _ref.column,
    propColumnIndex = _ref$column.propColumnIndex,
    resizable = _ref$column.resizable,
    width = _ref$column.width,
    restProps = _objectWithoutProperties(_ref, _excluded);
  var _useContext = useContext(TableContext),
    table = _useContext.table;
  var _useState = useState({
      width: width,
      x: 0,
      h: '100%',
      isResizing: false
    }),
    _useState2 = _slicedToArray(_useState, 2),
    offset = _useState2[0],
    setOffset = _useState2[1];
  var resizeRef = useRef();
  var tmpRef = useRef();
  useEffect(function () {
    if (!offset.isResizing && offset.width !== width) {
      setOffset(function (prevState) {
        return _objectSpread(_objectSpread({}, prevState), {}, {
          width: width,
          x: 0
        });
      });
    }
  });
  if (resizable) {
    var onResizeStart = function onResizeStart() {
      if (!tmpRef.current) {
        tmpRef.current = util.closest(resizeRef.current, function (el) {
          return el.classList.contains('virtual-table');
        });
      }
      tmpRef.current.style.pointerEvents = 'none';
      document.body.style.userSelect = 'none';
      document.body.style.cursor = 'col-resize';
      resizeRef.current.parentElement.classList.add('is-resizing');
    };
    var onResize = function onResize(_e, _ref2) {
      var size = _ref2.size;
      if (size.width !== offset.width) {
        setOffset({
          width: size.width,
          x: size.width - width,
          h: table.state.height,
          isResizing: true
        });
      }
    };
    var onResizeStop = function onResizeStop(_e, _ref3) {
      var size = _ref3.size;
      tmpRef.current && (tmpRef.current.style.pointerEvents = 'auto');
      document.body.style.userSelect = '';
      document.body.style.cursor = '';
      resizeRef.current.parentElement.classList.remove('is-resizing');
      setOffset(function (prev) {
        return _objectSpread(_objectSpread({}, prev), {}, {
          x: 0,
          h: '100%',
          isResizing: false
        });
      });
      if (size.width !== width) {
        table.refreshView({
          state: function state() {
            var columns = table.state.columns;
            columns[propColumnIndex].offsetWidth = size.width;
            return {
              columns: _toConsumableArray(columns)
            };
          },
          rowColumnIndex: {
            columnIndex: 0
          },
          cacheState: true
        });
      }
    };
    return /*#__PURE__*/_jsx(Resizable, {
      width: offset.width,
      height: 0,
      handle: function handle(_, ref) {
        var setRef = function setRef(nodeCurrent) {
          ref.current = nodeCurrent;
          resizeRef.current = nodeCurrent;
        };
        return /*#__PURE__*/_jsx("span", {
          className: "stop-propagation resizable-handle".concat(offset.isResizing ? ' is-resizing' : ''),
          ref: setRef,
          style: {
            transform: "translateX(".concat(offset.x, "px)"),
            height: offset.h
          }
        });
      },
      onResizeStart: onResizeStart,
      onResize: onResize,
      onResizeStop: onResizeStop,
      draggableOpts: {
        enableUserSelectHack: false
      },
      children: /*#__PURE__*/_jsx("div", _objectSpread({}, restProps))
    });
  } else {
    return /*#__PURE__*/_jsx("div", _objectSpread({}, restProps));
  }
};

/**
 * 编辑列头标记
 * @param editor
 * @param dataIndex
 * @constructor
 */
var EditFlag = function EditFlag(_ref4) {
  var editor = _ref4.editor,
    dataIndex = _ref4.dataIndex;
  var _useContext2 = useContext(TableContext),
    table = _useContext2.table;
  if (!editor || !table.props.editColumnIcon) {
    return null;
  }
  var required = editor.required;
  var style = {
    marginRight: 2,
    fontWeight: 'normal',
    opacity: 0.5,
    transform: 'scale(0.7)'
  };
  if (required) {
    style.color = 'var(--primary-color)';
  }
  if (util.isFunction(table.props.editColumnIcon)) {
    return table.props.editColumnIcon({
      table: table,
      dataIndex: dataIndex,
      editor: editor,
      style: style
    });
  }
  return /*#__PURE__*/_jsx(EditOutlined, {
    style: style
  });
};
var HeaderCell = function HeaderCell(_ref5) {
  var _column$groupIn;
  var column = _ref5.column,
    cellStyle = _ref5.cellStyle;
  var _useContext3 = useContext(TableContext),
    table = _useContext3.table;
  var title = column.title,
    width = column.width,
    dataIndex = column.dataIndex,
    columnIndex = column.columnIndex,
    headerTooltip = column.headerTooltip,
    headerStyle = column.headerStyle,
    columnSort = column.columnSort,
    sortable = column.sortable,
    header = column.header,
    filter = column.filter,
    originEditor = column.originEditor;
  var style = _objectSpread(_objectSpread({}, cellStyle), {}, {
    width: width
  }, convertStyle(headerStyle));
  if ((_column$groupIn = column.groupIn) !== null && _column$groupIn !== void 0 && _column$groupIn.length && !title && !header) {
    return /*#__PURE__*/_jsx("div", {
      style: _objectSpread(_objectSpread({}, style), {}, {
        height: 0
      })
    });
  }
  var headerCellClick = useRefCallback(function (e) {
    table.notify({
      e: e,
      column: column
    }, 'onHeaderCellClick');
  });
  sortable && (style.cursor = 'pointer');
  var renderIcon = function renderIcon(cStyle) {
    return /*#__PURE__*/_jsxs("span", {
      className: "stop-propagation",
      style: cStyle,
      children: [sortable && /*#__PURE__*/_jsx(OrderIcon, {
        column: column
      }), filter && /*#__PURE__*/_jsx(FilterIcon, {
        column: column,
        table: table
      })]
    });
  };
  var titleInfo = util.isFunction(header) ? header({
    title: title,
    dataIndex: dataIndex,
    column: column,
    table: table
  }) : header || title;
  var info = util.isString(titleInfo) ? /*#__PURE__*/_jsx("span", {
    className: "nowrap",
    children: titleInfo
  }) : titleInfo;
  return /*#__PURE__*/_jsxs(HeaderCellResize, {
    index: columnIndex,
    column: column,
    onClick: headerCellClick,
    className: util.classNames('header-cell', "".concat(columnSort ? 'react-sortable' : '')),
    style: style,
    children: [style.textAlign === 'right' && renderIcon({
      marginRight: 4,
      display: 'inline-block'
    }), /*#__PURE__*/_jsx(EditFlag, {
      editor: originEditor,
      dataIndex: dataIndex
    }), headerTooltip ? /*#__PURE__*/_jsx(Tooltip, {
      title: info,
      overflow: true,
      children: info
    }) : info, style.textAlign !== 'right' && renderIcon({
      marginLeft: 4,
      position: 'absolute',
      display: 'flex',
      right: 8
    })]
  }, columnIndex);
};
var FixedHeader = function FixedHeader(_ref6) {
  var type = _ref6.type,
    children = _ref6.children;
  var _useContext4 = useContext(TableContext),
    _useContext4$table = _useContext4.table,
    groupColumns = _useContext4$table.groupColumns,
    cellStyle = _useContext4$table.cellStyle,
    _useContext4$columns = _useContext4.columns,
    headerLineHeight = _useContext4$columns.headerLineHeight,
    unUsedWidth = _useContext4$columns.unUsedWidth;
  var columns = groupColumns[type];
  if (columns.length === 0) {
    return children ? /*#__PURE__*/_jsx("div", {
      style: {
        display: 'inline-flex',
        position: 'absolute',
        right: 0,
        zIndex: -1,
        top: 0,
        bottom: 0
      },
      children: children
    }) : /*#__PURE__*/_jsx("span", {});
  }
  var style = type === 'left' ? {
    left: 0,
    zIndex: 1
  } : {
    right: 0,
    zIndex: 2,
    marginRight: unUsedWidth
  };
  return /*#__PURE__*/_jsxs("div", {
    className: "fc fixed-cell-".concat(type),
    style: style,
    children: [getGroupContainer(columns, headerLineHeight, cellStyle), children]
  });
};
function getGroupContainer(groupColumns, headerLineHeight, cellStyle, SortCell) {
  return groupColumns.map(function (groupColumn, groupIndex) {
    if (groupColumn.children) {
      return /*#__PURE__*/_jsxs("div", {
        style: {
          height: '100%',
          display: 'inline-flex',
          flexDirection: 'column'
        },
        children: [/*#__PURE__*/_jsx("div", {
          className: "column-group",
          style: {
            height: headerLineHeight,
            width: '100%',
            fontSize: 14,
            justifyContent: 'center'
          },
          children: /*#__PURE__*/_jsx("div", {
            className: "nowrap",
            style: {
              width: 0,
              minWidth: '100%',
              height: '100%',
              alignItems: 'center',
              justifyContent: 'center',
              paddingRight: 1,
              display: 'flex'
            },
            children: util.isFunction(groupColumn.groupTitle) ? groupColumn.groupTitle({
              column: groupColumn
            }) : groupColumn.groupTitle
          })
        }), /*#__PURE__*/_jsx("div", {
          style: {
            flex: 1,
            display: 'inline-flex'
          },
          children: getGroupContainer(groupColumn.children, headerLineHeight, cellStyle, null)
        })]
      }, groupIndex);
    } else {
      var ColumnCell = groupColumn.columnSort ? SortCell !== null && SortCell !== void 0 ? SortCell : HeaderCell : HeaderCell;
      return /*#__PURE__*/_jsx(ColumnCell, {
        index: groupColumn.propColumnIndex,
        disabled: !groupColumn.columnSort,
        cellStyle: cellStyle,
        column: groupColumn
      }, (groupColumn.dataIndex || '-') + groupIndex);
    }
  });
}
function getSortEnd(table) {
  return function (_ref7) {
    var oldIndex = _ref7.oldIndex,
      newIndex = _ref7.newIndex;
    if (oldIndex !== newIndex) {
      table.refreshView({
        state: function state() {
          var columns = table.state.columns;
          var item = columns.splice(oldIndex, 1)[0];
          columns.splice(newIndex, 0, item);
          return {
            columns: _toConsumableArray(columns)
          };
        },
        rowColumnIndex: {
          columnIndex: 0
        },
        cacheState: true
      });
    }
  };
}

/**
 * 拖拽表头进行列排序
 * @constructor
 */
var SortableHeaderContainer = function SortableHeaderContainer() {
  var _gridIns$state;
  var _useContext5 = useContext(TableContext),
    table = _useContext5.table,
    _useContext5$columns = _useContext5.columns,
    _useContext5$columns$ = _useContext5$columns.fixedColumns,
    left = _useContext5$columns$.left,
    right = _useContext5$columns$.right,
    columnSort = _useContext5$columns.columnSort,
    groupable = _useContext5$columns.groupable,
    headerLineHeight = _useContext5$columns.headerLineHeight;
  var gridIns = table.outRef.current,
    groupColumns = table.groupColumns,
    bordered = table.props.bordered;
  var headStyle = {
    whiteSpace: 'nowrap',
    display: 'inline-flex',
    height: '100%',
    paddingLeft: left.width,
    paddingRight: right.width,
    transform: "translateX(-".concat((gridIns === null || gridIns === void 0 || (_gridIns$state = gridIns.state) === null || _gridIns$state === void 0 ? void 0 : _gridIns$state.scrollLeft) || 0, "px)")
  };
  var zwLeft = !groupable && !bordered && left.width > 0;
  var zwStyle = {
    padding: 0,
    width: 0,
    left: 1,
    zIndex: 2
  };
  var _useDraggableSort = useDraggableSort(columnSort, HeaderCell),
    SortContainer = _useDraggableSort.SortContainer,
    SortCell = _useDraggableSort.SortElement;
  if (SortContainer) {
    var shouldCancelStart = function shouldCancelStart(e) {
      return domContains('stop-propagation', e.target);
    };
    return /*#__PURE__*/_jsx(SortContainer, {
      axis: "x",
      lockAxis: "xy",
      pressDelay: 250,
      shouldCancelStart: shouldCancelStart,
      onSortEnd: getSortEnd(table),
      children: /*#__PURE__*/_jsxs("span", {
        style: headStyle,
        className: "normal-cells",
        children: [zwLeft && /*#__PURE__*/_jsx("div", {
          className: "header-cell",
          style: zwStyle
        }), getGroupContainer(groupColumns.normal, headerLineHeight, table.cellStyle, SortCell), right.width > 0 && /*#__PURE__*/_jsx("div", {
          className: "header-cell",
          hidden: true
        })]
      })
    });
  } else {
    return /*#__PURE__*/_jsxs("span", {
      style: headStyle,
      className: "normal-cells",
      children: [zwLeft && /*#__PURE__*/_jsx("div", {
        className: "header-cell",
        style: zwStyle
      }), getGroupContainer(groupColumns.normal, headerLineHeight, table.cellStyle), right.width > 0 && /*#__PURE__*/_jsx("div", {
        className: "header-cell",
        hidden: true
      })]
    });
  }
};
var HeaderMenu = function HeaderMenu(_ref8) {
  var showHeaderMenu = _ref8.showHeaderMenu;
  var _useContext6 = useContext(TableContext),
    table = _useContext6.table,
    headerLineHeight = _useContext6.columns.headerLineHeight;
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    visible = _useState4[0],
    setVisible = _useState4[1];
  var _useState5 = useState([]),
    _useState6 = _slicedToArray(_useState5, 2),
    change = _useState6[0],
    setChange = _useState6[1];
  var _onChange = useRefCallback(function (column, columnIndex, e) {
    var index = change.indexOf(columnIndex);
    column.hidden = !e.target.checked;
    if (index > -1) {
      change.splice(index, 1);
    } else {
      change.push(columnIndex);
    }
    setChange(_toConsumableArray(change));
  });
  useIUPEffect(function () {
    if (change.length > 0) {
      table.refreshView({
        state: {
          columns: _toConsumableArray(table.state.columns)
        },
        rowColumnIndex: {
          columnIndex: 0
        },
        cacheState: true
      });
      setChange([]);
    }
  }, [change]);
  var onVisibleChange = function onVisibleChange(flag) {
    setVisible(flag);
    flag && setChange([]);
  };
  var items = useMemo(function () {
    var columnItems = table.state.columns.filter(function (c) {
      return !c.propHidden;
    });
    var DraggableHandle = SortableHandle(function (_ref9) {
      var disabled = _ref9.disabled;
      return /*#__PURE__*/_jsx(HolderOutlined, {
        style: {
          fontSize: 14,
          opacity: disabled ? 0.1 : 0.4,
          cursor: disabled ? '' : 'grab',
          marginRight: 7,
          padding: '3px 3px 3px 0'
        }
      });
    });
    var DraggableItem = SortableElement(function (_ref10) {
      var children = _ref10.children,
        column = _ref10.column;
      var setFixed = function setFixed(fixed) {
        return function () {
          column.fixed = fixed;
          table.refreshView({
            state: {
              columns: _toConsumableArray(columnItems)
            },
            rowColumnIndex: {
              columnIndex: 0
            },
            cacheState: true
          });
        };
      };
      return /*#__PURE__*/_jsxs("div", {
        className: "column-setting-item",
        style: {
          padding: '5px 12px',
          display: 'flex',
          userSelect: 'none',
          minWidth: 120
        },
        children: [/*#__PURE__*/_jsx(DraggableHandle, {
          disabled: column.hidden
        }), /*#__PURE__*/_jsx("div", {
          style: {
            flex: 1
          },
          children: children
        }), /*#__PURE__*/_jsxs("span", {
          className: "column-fixed-icon",
          style: {
            color: cssVar.primaryColor,
            fontSize: 14,
            gap: 5,
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'right',
            width: 35
          },
          children: [(!column.fixed || column.fixed === 'right') && /*#__PURE__*/_jsx(Tooltip, {
            title: "\u56FA\u5B9A\u5728\u5DE6\u4FA7",
            children: /*#__PURE__*/_jsx(VerticalAlignTopOutlined, {
              onClick: setFixed('left')
            })
          }), column.fixed && /*#__PURE__*/_jsx(Tooltip, {
            title: "\u53D6\u6D88\u56FA\u5B9A",
            children: /*#__PURE__*/_jsx(VerticalAlignMiddleOutlined, {
              onClick: setFixed(false)
            })
          }), column.fixed !== 'right' && /*#__PURE__*/_jsx(Tooltip, {
            title: "\u56FA\u5B9A\u5728\u53F3\u4FA7",
            children: /*#__PURE__*/_jsx(VerticalAlignBottomOutlined, {
              onClick: setFixed('right')
            })
          })]
        })]
      });
    });
    var tmp = [[], [], [], []];
    var left = tmp[0],
      center = tmp[1],
      right = tmp[2],
      _items = tmp[3];
    columnItems.forEach(function (column) {
      var header = column.header,
        title = column.title,
        dataIndex = column.dataIndex,
        propColumnIndex = column.propColumnIndex,
        hidden = column.hidden,
        fixed = column.fixed,
        _column$editor = column.editor,
        editor = _column$editor === void 0 ? {} : _column$editor;
      var collection = fixed ? fixed === 'right' ? 2 : 0 : 1;
      var headTxt = util.isFunction(header) ? header({
        title: title,
        dataIndex: dataIndex,
        column: column,
        table: table
      }) : header || title || dataIndex;
      var item = {
        key: "".concat(dataIndex, "_").concat(propColumnIndex),
        label: /*#__PURE__*/_jsx(DraggableItem, {
          index: propColumnIndex,
          collection: collection,
          disabled: hidden,
          column: column,
          children: /*#__PURE__*/_jsx(Checkbox, {
            onChange: function onChange(e) {
              return _onChange(column, propColumnIndex, e);
            },
            disabled: editor === null || editor === void 0 ? void 0 : editor.required,
            style: {
              whiteSpace: 'nowrap'
            },
            defaultChecked: !hidden,
            children: headTxt
          })
        })
      };
      if (collection === 0) {
        left.push(item);
      } else if (collection === 1) {
        center.push(item);
      } else {
        right.push(item);
      }
    });
    left.length > 0 && _items.push({
      label: '固定在左侧',
      key: 'left',
      type: 'group',
      children: left
    });
    center.length > 0 && _items.push({
      label: '不固定',
      key: 'center',
      type: 'group',
      children: center
    });
    right.length > 0 && _items.push({
      label: '固定在右侧',
      key: 'right',
      type: 'group',
      children: right
    });
    return [{
      label: /*#__PURE__*/_jsxs(Space.Compact, {
        block: true,
        style: {
          justifyContent: 'space-between',
          alignItems: 'center',
          backgroundColor: '#fff',
          cursor: 'default',
          padding: '5px 12px'
        },
        children: ["\u5217\u8BBE\u7F6E", /*#__PURE__*/_jsx("a", {
          onClick: function onClick() {
            util.setCache(table.stateId, undefined);
            table.refreshView({
              rowColumnIndex: {
                columnIndex: 0
              },
              cacheState: false,
              state: {
                columns: table._initColumns()
              }
            });
          },
          children: "\u91CD\u7F6E"
        })]
      }),
      key: 'op'
    }, {
      type: 'divider'
    }].concat(_toConsumableArray(_items));
  }, [showHeaderMenu, table.state.columns]);
  var dropdownRender = useReturnCallback(function () {
    var DraggableContainer = SortableContainer(function () {
      return /*#__PURE__*/_jsx("div", {
        style: {
          padding: 5
        },
        children: items.map(function (itm) {
          var _itm$children;
          return itm.type === 'group' ? /*#__PURE__*/_jsxs("ul", {
            style: {
              margin: 0,
              padding: 0
            },
            children: [/*#__PURE__*/_jsx("div", {
              style: {
                color: 'rgba(0,0,0,0.45)',
                padding: '5px 12px'
              },
              children: itm.label
            }, 'group'), (_itm$children = itm.children) === null || _itm$children === void 0 ? void 0 : _itm$children.map(function (c) {
              return /*#__PURE__*/React.cloneElement(c.label, {
                key: c.key
              });
            })]
          }, itm.key) : itm.type === 'divider' ? /*#__PURE__*/_jsx(Divider, {
            style: {
              margin: 4
            }
          }, 'divider') : ( /*#__PURE__*/React.cloneElement(itm.label, {
            key: itm.key
          }));
        })
      });
    });
    return /*#__PURE__*/_jsx(DraggableContainer, {
      useDragHandle: true,
      onSortEnd: getSortEnd(table),
      helperClass: "row-dragging menu-checkbox"
    });
  }, [items]);
  var rendererElement = function rendererElement() {
    var createPortal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    if (util.isFunction(showHeaderMenu)) {
      return showHeaderMenu({
        table: table
      });
    }
    return /*#__PURE__*/_jsx(Popover, {
      className: util.classNames({
        advanced: !createPortal
      }),
      placement: "bottomRight",
      overlayStyle: {
        marginRight: 1,
        padding: 0
      },
      overlayInnerStyle: {
        padding: 0,
        maxHeight: 400,
        overflowY: 'auto'
      },
      content: dropdownRender,
      trigger: ['click'],
      open: visible,
      arrow: false,
      onOpenChange: onVisibleChange,
      children: showHeaderMenu.icon || /*#__PURE__*/_jsx(MoreOutlined, {
        style: {
          height: headerLineHeight - 1
        }
      })
    });
  };
  if (showHeaderMenu.inTableAlert) {
    if (!table.settingContainer) {
      table.settingContainer = document.createElement('div');
      table.settingContainer.style.display = 'flex';
    }
    return /*#__PURE__*/ReactDOM.createPortal(rendererElement(true), table.settingContainer);
  }
  if (showHeaderMenu.getContainer) {
    var container = util.isFunction(showHeaderMenu.getContainer) ? showHeaderMenu.getContainer() : document.getElementById(showHeaderMenu.getContainer);
    if (container) {
      return /*#__PURE__*/ReactDOM.createPortal(rendererElement(true), container);
    }
  }
  return rendererElement();
};
var TableHeader = /*#__PURE__*/React.memo(function () {
  var _useContext7 = useContext(TableContext),
    table = _useContext7.table,
    groupable = _useContext7.columns.groupable;
  var headerHeight = table.headerHeight;
  var _table$props = table.props,
    _table$props$hiddenHe = _table$props.hiddenHeader,
    hiddenHeader = _table$props$hiddenHe === void 0 ? false : _table$props$hiddenHe,
    _table$props$headerMe = _table$props.headerMenu,
    headerMenu = _table$props$headerMe === void 0 ? true : _table$props$headerMe;
  var headContainerStyle = {
    height: headerHeight
  };
  var _useState7 = useState(getScrollBarInfo().width),
    _useState8 = _slicedToArray(_useState7, 1),
    scrollBarWidth = _useState8[0];
  var showHeaderMenu = table.state.columns.length > 0 ? headerMenu : false;
  if (hiddenHeader || headerHeight <= 1) {
    return null;
  }
  return /*#__PURE__*/_jsxs("div", {
    ref: table.headerRef,
    className: "virtual-table-header".concat(groupable ? ' header-group' : ''),
    style: headContainerStyle,
    children: [/*#__PURE__*/_jsx(FixedHeader, {
      type: "left"
    }), /*#__PURE__*/_jsx(SortableHeaderContainer, {}), /*#__PURE__*/_jsx(FixedHeader, {
      type: "right",
      children: /*#__PURE__*/_jsx("span", {
        className: "scrollbar-placeholder",
        style: {
          width: scrollBarWidth,
          display: 'none'
        }
      })
    }), showHeaderMenu && /*#__PURE__*/_jsx(HeaderMenu, {
      showHeaderMenu: showHeaderMenu
    })]
  });
});
export { TableHeader };